import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/utils/color.dart';
import 'package:loxen/utils/config.dart';

class ItemBean {
  //是否选择
  bool select = false;

  //是否超出
  bool isBeyond;

  //省
  String province;

  //市
  String city;

  //区
  String district;

  //详细地址
  String detailedAddress;

  //名字
  String userName;

  //电话
  String telephone;

  ItemBean(this.select, this.isBeyond, this.province, this.city, this.district,
      this.detailedAddress, this.userName, this.telephone);
}

class AdderssItemCard extends StatelessWidget {
  final ItemBean bean;
  final Function() onClick;
  final Function() onEdit;
  final bool showDistance;

  const AdderssItemCard({Key key, this.bean, this.onClick, this.onEdit, this.showDistance})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TweenAnimationBuilder(
        tween: Tween<double>(begin: 0, end: 1),
        duration: Duration(milliseconds: 500),
        builder: (_, double data, __) {
          return Card(
            elevation: data * 5,
            child: Opacity(
              opacity: data,
              child: Container(
                child: InkWell(
                  onTap: onClick,
                  child: Row(
                    children: [
                      Padding(
                        padding: EdgeInsets.only(left: 20.w),
                        child: Image.asset(
                          bean.select ? 'images/location_true.png' : 'images/location_false.png',
                          width: 76.w,
                          height: 76.w,
                        ),
                      ),
                      Expanded(
                        child: Padding(
                          padding: EdgeInsets.only(left: 30.w),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Padding(
                                padding: EdgeInsets.only(top: 30.h, right: 20.w),
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        '${bean.province} ${bean.city} ${bean.district}',
                                        style: TextStyle(
                                          fontSize: 24.sp,
                                          color: bean.isBeyond && showDistance
                                              ? Colours.secondary_text
                                              : Colours.main_text,
                                        ),
                                      ),
                                    ),
                                    bean.isBeyond && showDistance
                                        ? Text(
                                            '超出配送范围',
                                            style: TextStyle(
                                              fontSize: 22.sp,
                                              color: Colours.app_main,
                                            ),
                                          )
                                        : Constants.empty
                                  ],
                                ),
                              ),
                              Padding(
                                padding: EdgeInsets.only(top: 10.h),
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        bean.detailedAddress,
                                        style: TextStyle(
                                          fontSize: 28.sp,
                                          color: bean.isBeyond && showDistance
                                              ? Colours.secondary_text
                                              : Colours.main_text,
                                          fontWeight: FontWeight.bold,
                                        ),
                                      ),
                                    ),
                                    Padding(
                                      padding: EdgeInsets.only(right: 10.w),
                                      child: IconButton(
                                        icon: Image.asset(
                                          'images/editAddress.png',
                                          width: 30.w,
                                          height: 30.w,
                                        ),
                                        onPressed: onEdit,
                                      ),
                                    )
                                  ],
                                ),
                              ),
                              Padding(
                                padding: EdgeInsets.only(top: 30.h, bottom: 30.h),
                                child: Text(
                                  '${bean.userName}   ${bean.telephone}',
                                  style: TextStyle(
                                    fontSize: 24.sp,
                                    color: bean.isBeyond && showDistance
                                        ? Colours.secondary_text
                                        : Colours.main_text,
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          );
        });
    return Card(
      elevation: 5,
      child: Container(
        child: InkWell(
          onTap: onClick,
          child: Row(
            children: [
              Padding(
                padding: EdgeInsets.only(left: 20.w),
                child: Image.asset(
                  bean.select ? 'images/location_true.png' : 'images/location_false.png',
                  width: 76.w,
                  height: 76.w,
                ),
              ),
              Expanded(
                child: Padding(
                  padding: EdgeInsets.only(left: 30.w),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(
                        padding: EdgeInsets.only(top: 30.h, right: 20.w),
                        child: Row(
                          children: [
                            Expanded(
                              child: Text(
                                '${bean.province} ${bean.city} ${bean.district}',
                                style: TextStyle(
                                  fontSize: 24.sp,
                                  color: bean.isBeyond && showDistance
                                      ? Colours.secondary_text
                                      : Colours.main_text,
                                ),
                              ),
                            ),
                            bean.isBeyond && showDistance
                                ? Text(
                                    '超出配送范围',
                                    style: TextStyle(
                                      fontSize: 22.sp,
                                      color: Colours.app_main,
                                    ),
                                  )
                                : Constants.empty
                          ],
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 10.h),
                        child: Row(
                          children: [
                            Expanded(
                              child: Text(
                                bean.detailedAddress,
                                style: TextStyle(
                                  fontSize: 28.sp,
                                  color: bean.isBeyond && showDistance
                                      ? Colours.secondary_text
                                      : Colours.main_text,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                            Padding(
                              padding: EdgeInsets.only(right: 10.w),
                              child: IconButton(
                                icon: Image.asset(
                                  'images/editAddress.png',
                                  width: 30.w,
                                  height: 30.w,
                                ),
                                onPressed: onEdit,
                              ),
                            )
                          ],
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.only(top: 30.h, bottom: 30.h),
                        child: Text(
                          '${bean.userName}   ${bean.telephone}',
                          style: TextStyle(
                            fontSize: 24.sp,
                            color: bean.isBeyond && showDistance
                                ? Colours.secondary_text
                                : Colours.main_text,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
